<?php session_start();
    if(!isset($_SESSION['login']))
    {
        $_SESSION['login'] = false;
    }
     $_SESSION['page'] = "profile"; 
?>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Register</title>
        <script type="text/javascript" src="script/home.js"></script>
    <link rel="stylesheet" type="text/css" title="T1" href="stylesheet/progin.css" id="link_theme" />
	<link rel="stylesheet" type="text/css" title="T1" href="stylesheet/posting.css" />
		<meta name="description" content="RERGag, Make You Laughing" />
		<meta name="keywords" content="laugh" />
		<meta name="author" content="Robertus Theodore" />
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    </head>
    <body>
        <?php include 'header.php'; ?>
		
        <div class="main_container">
            <div id="preview"></div>
        <?php
    function displayContent($row,$result){
        while ($row = mysql_fetch_array($result)){
            if($row['content_type']== 'link'){
                echo "<h1>".$row['title']."</h1>";
                echo "<h2>".$row['content_filled']."</h2>";
                echo "<h3>".$row['content_description']."</h3>";
                echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
            }
            if($row['content_type']== 'image'){
                echo "<h1>".$row['title']."</h1>";
                echo "<img src='".$row['content_filled']."' height=500px; ></img>";
                echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
            }
            if($row['content_type']== 'video'){
                echo "<h1>".$row['title']."</h1>";
                echo $row['content_filled'];
                echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
            }
            echo"<script type='text/javascript'>"; //hitung nilai like dan dislike dulu!
            echo "likeUpdater(".$row['id_content']."); dislikeUpdater(".$row['id_content'].");";
            echo "</script>";

            echo"<input id='like_".$row['id_content']."' class='like_button' type='image' src='images/like_button.jpg' onclick='like(".$_SESSION['user_name'].",".$row['id_content'].")'/>";
            echo"<input class='total_like_class' type='text' disabled='disabled' id='total_like_".$row['id_content']."' />";
            echo"<input id='dislike_'".$row['id_content']." class='like_button' type='image' src='images/dislike_button.jpg' onclick='dislike(".$_SESSION['user_name'].",".$row['id_content'].")'/>";
            echo"<input class='total_dislike_class' type='text' disabled='disabled' id='total_dislike_".$row['id_content']."' />";
        }
    }

    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("progin_171_13509008", $con);

    $queryUser = "SELECT * FROM user where user_name = '".$_SESSION['user_name']."'";
    $queryAchievement = "SELECT achievement_name FROM achievement where id_achievement=(SELECT id_achievement FROM user_achievement where user_name ='".$_SESSION['user_name']."')";
    $queryComment = "SELECT id_comment FROM user_comment where user_name ='".$_SESSION['user_name']."'";
    $queryContent = "SELECT id_content FROM content where user_name ='".$_SESSION['user_name']."'";
    $resultQueryUser = mysql_query($queryUser);
    $resultQueryAchievement = mysql_query($queryAchievement);
    $resultQueryComment = mysql_query($queryComment);
    $resultQueryContent = mysql_query($queryContent);
    $user_name = $_SESSION['user_name'];
    $data_user = mysql_fetch_array($resultQueryUser);
    $rowAchievement = mysql_num_rows($resultQueryAchievement);
    $rowComment = mysql_num_rows($resultQueryComment);
    $rowContent = mysql_num_rows($resultQueryContent);
    echo "<h1>".$user_name."</h1> </br/>";
    echo "<img src='".$data_user['avatar']."' height=200px; ></img>"."</br/>";
    echo $data_user['email']."</br/>";
    echo $data_user['gender']."</br/>";
    echo $data_user['about_me']."</br/>";
    echo "Achievement : </br>";
    if($rowAchievement == 0){
        echo "Y U NO Get Achievement?!</br>";
    }else{
        $data_achievement = mysql_fetch_array($resultQueryAchievement);
        for($i = 0 ; $i < $rowAchievement ; $i++){
            echo $data_achievement[$i]."</br/>";
        }
    }
    echo $rowComment."</br/>";
    echo $rowContent."</br/>";
    $query = "select distinct content.content_description, content.id_content, user_name, content.title, content.content_type, content.content_filled from 
                                        (select id_content, TIMESTAMPDIFF(SECOND, posting_time, now()) as time from content order by time) time_order, content
                                        where user_name = '".$_SESSION['user_name']."' order by time_order.time";
    $result = mysql_query($query);
    $row = mysql_num_rows($result);
    if($row == 0){
        echo "No tag exists in database";
    }else{
        displayContent($row,$result);
    }
?>
        <script type="text/javascript" src="script/posting.js"></script>
        <script type="text/javascript" src="script/progin.js"></script>
        </div>
    </body>
</html>